 require(["common", "eventManager", "coAjax", "queryString", "href", "hash_routie", "WX", "touch", "jQuery.qrcode"], function(jSouper, eventManager, coAjax, QueryString, href, hash_routie, WX, touch) {
 	eventManager.on("goods_detail:goods-info-load", function() {
 		hash_routie.emit("*");
 	});
 	hash_routie.on("goods_details", function() {
 		// 详情缩放detailsscale
 		App.set("checkAdd", false);
 		var queryString = new QueryString(location.hash);

 		var goods_id = queryString.get("id");
 		//记录访问量
 		coAjax.post(appConfig.hot_add + goods_id, function(result) {
 			App.set("$Cache.hot_num", result.result);
 		});
 		//参数错误，返回首页
 		if (!goods_id) {
 			href.toMain();
 		}
 		// 获取商品详情
 		coAjax.get(appConfig.goods.detail + goods_id, function(result) {
 			var goods_info = result.result;
 			//处理数据格式
 			goods_info.price = +goods_info.price || 0;
 			goods_info.price_toFixed_2 = goods_info.price.toFixed(2);
 			goods_info.fare = +goods_info.fare || 0;
 			goods_info.fare_toFixed_2 = goods_info.fare.toFixed(2);
 			App.set("goods_detail", goods_info);
 			eventManager.emit("goods_detail:goods-info-load", goods_info);
 			var $box = $("#detailsscale");
 			var $contentbox = $("#contentbox");
 			var _scaleCount = false;
 			touch.on($box, "doubletap", function() {
 				if (_scaleCount) {
 					_scaleCount = false;
 					$box.css({
 						"transform": "scale(1)",
 						"-webkit-transform": "scale(1)",
 						width: $box.width() / 2 + "px"
 					});
 					return;
 				};
 				_scaleCount = true;
 				$box.css({
 					"transform": "scale(2)",
 					"-webkit-transform": "scale(2)",
 					"width": $box.width() * 2 + "px"
 				});
 			});
 		});
 		//获取评价数据
 		// coAjax.get(appConfig.user.can_eval + goods_id, function(result) {
 		// 	App.set("$Cache.eval.can_evaluation_able", result.result.can_evaluation_able);
 		// });
 		function _get_cart_success(result) {
 			var cart_detail = result.result;
 			App.set("user.cart_detail", cart_detail);
 			App.set("$Cache.cart.total_price", Model.Observer(function() {
 				var cart_detail = App.get("user.cart_detail");
 				var total_price = 0;
 				cart_detail.forEach(function(cart) {
 					cart.goods_info.forEach(function(goods_info) {
 						total_price += goods_info.goods.price * goods_info.num;
 					});
 				});
 				return total_price;
 			}));

 			alert("success", "添加成功");
 		};

 		function _get_cart_error(errorCode, xhr, errorMsg) {
 			console.log("%c" + errorCode + ": " + errorMsg, "color:orange;font-size:14px; text-shadow: 0 1px 0 #ccc;");
 			alert("error", errorMsg);
 		};
 		App.set("$Event.goods.add_to_cart", function(e) {
 			var cart_item = {
 				goods_id: App.get("goods_detail._id"),
 				num: App.get("$Cache.goods_details.buy_number")
 			};
 			if (App.get("loginer")) {
 				coAjax.post(appConfig.user.cart, cart_item, _get_cart_success, _get_cart_error);
 			} else {
 				alert('error', '添加商品前请先登陆');
 				var cache_cart = LS.get("$Cache.cart");
 				try {
 					cache_cart = JSON.parse(cache_cart);
 				} catch (e) {
 					console.log(e)
 				}
 				if (!(cache_cart instanceof Array)) {
 					cache_cart = [];
 				}
 				cache_cart.push(cart_item)
 			}
 		});
 		App.set("$Event.goods.selectRecUrl", function(e) {
 			//全选
 			this.select && this.select();
 		});
 		eventManager.is(App.get("loginer.collect"), "getLoginer", function() {
 			var collect = App.get("loginer.collect") || [];
 			_is_collect_goods(collect);
 		});

 		function _is_collect_goods(collect) {
 			var result = false;
 			if (jSouper.indexOf(collect, goods_id) !== -1) {
 				result = true;
 			}
 			App.set("$Cache.goods_detail.is_collect", result);
 		}
 		App.set("$Event.goods.collect_toggle", function() {
 			if (App.get("$Cache.goods_detail.is_collect")) {
 				coAjax["delete"](appConfig.user.collect_remove, {
 					goods_id: goods_id
 				}, function(result) {
 					alert("已经取消收藏");
 					_is_collect_goods(result.result);
 				}, function(errorCode, xhr, errorMsg) {
 					alert("error", errorMsg)
 				});
 			} else {
 				coAjax.post(appConfig.user.collect_add, {
 					goods_id: goods_id
 				}, function(result) {
 					alert("success", "收藏成功");
 					_is_collect_goods(result.result);
 				}, function(errorCode, xhr, errorMsg) {
 					alert("error", errorMsg)
 				});
 			}
 		});
 		// 分享
 		// 微博
 		App.set('$Event.shareToWeibo', function() {
 			var title = "我觉得#" + App.get("goods_detail.goods_name") + "#不错，跟大家分享一下";
 			console.log(title);
 			var pic = App.get("goods_detail.preview_img_url") + "?imageView/1/w/100/h/100";
 			var rLink = location.host.toString() + "/mobile.main.html#default/goods_details?id=" + App.get('goods_detail._id') + "&rcid=" + App.get("loginer._id");
 			var site = location.host;
 			var summary = App.get('goods_detail.intro');
 			window.open("http://service.weibo.com/share/share.php?url=" + encodeURIComponent(rLink) + "&title=" + encodeURIComponent(title.replace(/&nbsp;/g, " ").replace(/<br \/>/g, " ")) + "&pic=" + encodeURIComponent(pic),
 				"分享至新浪微博",
 				"toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no");
 		});
 		// QQ空间
 		App.set('$Event.shareQzone', function() {
 			var title = "我觉得#" + App.get("goods_detail.goods_name") + "#不错，跟大家分享一下";
 			console.log(title);
 			var pic = App.get("goods_detail.preview_img_url") + "?imageView/1/w/100/h/100";
 			var rLink = location.host.toString() + "/mobile.main.html#default/goods_details?id=" + App.get('goods_detail._id') + "&rcid=" + App.get("loginer._id");
 			var site = location.host;
 			var summary = App.get('goods_detail.intro');
 			window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?title=' +
 				encodeURIComponent(title) + '&url=' + encodeURIComponent(rLink) + '&summary=' +
 				encodeURIComponent(summary) + '&site=' + encodeURIComponent(site), '_blank', 'scrollbars=no,status=no,resizable=yes');
 		});

 	});
 	App.set("$Event.checkAdd", function() {
 		App.model.toggle('checkAdd');
 	});
 	// 返回
 	App.set("$Event.detailGoBack", function() {
 		if (App.get("$Cache.page_index") > 0) {
 			window.history.back();
 		} else {
 			href.jump("/mobile.main.html#default/main");
 		}
 	});
 	App.set("$Event.show_share_link", function() {
 		App.model.toggle("$Cache.show_share_link");
 	});
 	// App.set("$Event.open_goods_content", function(e, vm) {
 	// 	var goodscontentWindow = window.open("/mobile.goodscontent.html");
 	// 	goodscontentWindow.ischao = true;
 	// 	var messenger = window.gg_messenger = new Messenger('goodscontent_page', 'goodscontent');
 	// 	messenger.addTarget(goodscontentWindow, "goodscontent_page");
 	// 	goodscontentWindow.onload = function() {
 	// 		While(goodscontentWindow, "_end_add", function() {
 	// 			messenger.targets['goodscontent_page'].send(App.get("goods_detail.detail_content"));
 	// 		});
 	// 	}
 	// });
 	// alert("_isWX:"+_isWX);

 });